<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>router动态菜单初始化</title>
</head>

<body>
	<script>
		const myJson = [{
			"id": 0,
			"createTime": "2020-07-16 16:08:03",
			"createUser": "admin",
			"icon": "video",
			"isDel": "2",
			"name": "店铺列表",
			"parentId": "0",
			"roleId": null,
			"sort": "1",
			"type": "1",
			"sonMenu": [
				{
					"createTime": "2020-07-16 16:07:19",
					"createUser": "admin",
					"icon": "video",
					"id": "7972015576021233664",
					"isDel": "2",
					"name": "店铺详情",
					"parentId": "7972015760595775488",
					"roleId": null,
					"sonMenu": null,
					"sort": "2",
					"type": "2",
					"url": "https://blog.csdn.net/gkx_csdn/article/details/88707785",
					"sonMenu": [
						{
							"createTime": "2020-07-16 16:07:19",
							"createUser": "admin",
							"icon": "video",
							"id": "7972015576021233664",
							"isDel": "2",
							"name": "店铺详情2",
							"parentId": "7972015760595775488",
							"roleId": null,
							"sonMenu": null,
							"sort": "2",
							"type": "2",
							"url": "https://blog.csdn.net/gkx_csdn/article/details/88707785",
						},
						{
							"createTime": "2020-07-16 16:07:19",
							"createUser": "admin",
							"icon": "video",
							"id": "7972015576021233664",
							"isDel": "2",
							"name": "店铺详情3",
							"parentId": "7972015760595775488",
							"roleId": null,
							"sonMenu": null,
							"sort": "2",
							"type": "2",
							"url": "https://blog.csdn.net/gkx_csdn/article/details/88707785",
						}
					]
				}
			]
		}]
		// json初始化
		function restJson(obj) {
			let newJsony = [];
			let children = [];
			obj.forEach((item) => {
				let items = {
					id: item.id,
					path: item.icon,
					name: item.name,
					meta: {
						title: item.name,
						icon: item.icon
					}
				}
				if (item.sonMenu && item.sonMenu.length >= 1) {
					children = restJson(item.sonMenu);
					children.length>=1&&(items.children = children);
				}
				newJsony.push(items)
			})
			return newJsony
		}
		console.log(restJson(myJson))
	</script>
</body>

</html>